package com.ruoyi.sgsc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sgsc.domain.orderdetails;
import com.ruoyi.sgsc.service.IorderdetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单详情Controller
 * 
 * @author wy
 * @date 2024-09-29
 */
@Anonymous
@RestController
@RequestMapping("/sgsc/orderdetails")
public class orderdetailsController extends BaseController
{
    @Autowired
    private IorderdetailsService orderdetailsService;

    /**
     * 查询订单详情列表
     */

    @GetMapping("/list")
    public TableDataInfo list(orderdetails orderdetails)
    {
        startPage();
        List<orderdetails> list = orderdetailsService.selectorderdetailsList(orderdetails);
        return getDataTable(list);
    }

    /**
     * 导出订单详情列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, orderdetails orderdetails)
    {
        List<orderdetails> list = orderdetailsService.selectorderdetailsList(orderdetails);
        ExcelUtil<orderdetails> util = new ExcelUtil<orderdetails>(orderdetails.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 获取订单详情详细信息
     */

    @GetMapping(value = "/{orderDetailId}")
    public AjaxResult getInfo(@PathVariable("orderDetailId") Long orderDetailId)
    {
        return success(orderdetailsService.selectorderdetailsByOrderDetailId(orderDetailId));
    }

    /***
     * 根据userId获取订单列表
     * @param userId
     * @return
     */
    @GetMapping(value = "/orderlist/{userId}")
    public AjaxResult getInfoByUserId(@PathVariable("userId") Long userId)
    {
        return success(orderdetailsService.selectorderdetailsByuserId(userId));
    }

    /**
     * 根据orderId获取订单列表
     * @param orderId
     * @return
     */
    @GetMapping(value = "/ordert/{orderId}")
    public AjaxResult getInfoByOrderId(@PathVariable("orderId") Long orderId)
    {
        return success(orderdetailsService.selectorderdetailsByOrderId(orderId));
    }

    /**
     * 新增订单详情
     */
    @PostMapping
    public AjaxResult add(@RequestBody orderdetails orderdetails)
    {
        return toAjax(orderdetailsService.insertorderdetails(orderdetails));
    }

    /**
     * 修改订单详情
     */

    @PutMapping
    public AjaxResult edit(@RequestBody orderdetails orderdetails)
    {
        return toAjax(orderdetailsService.updateorderdetails(orderdetails));
    }

    /**
     * 删除订单详情
     */
	@DeleteMapping("/{orderDetailIds}")
    public AjaxResult remove(@PathVariable Long[] orderDetailIds)
    {
        return toAjax(orderdetailsService.deleteorderdetailsByOrderDetailIds(orderDetailIds));
    }
}
